/**
* Author: fulishang
* Create Time  : 2016年8月4日,下午10:55:23
* Modify Time :
* Desc  : 
*/
package com.sam.si.file.processor;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

import org.apache.commons.io.FileUtils;

import com.sam.si.file.util.Constants;

public class FileCreator {

	public static void main(String[] args) throws IOException, InterruptedException {
		createFiles();
	}

	private static void createFiles() throws IOException, InterruptedException {
		createFile("file1.txt", "content");
		createFile("file2.txt", "another file");
		appendFile("file1.txt", " modified");
	}

	private static void createFile(String fileName, String content) throws IOException, InterruptedException {
		writeFile(fileName, content, false);
	}

	private static void appendFile(String fileName, String content) throws IOException, InterruptedException {
		writeFile(fileName, content, true);
	}

	private static void writeFile(String fileName, String content, boolean append)
			throws IOException, InterruptedException {
		File newFile = new File(Constants.ROUTER_FILE_DIRECTORY + fileName);
		FileUtils.writeStringToFile(newFile, content, Charset.forName("UTF-8"), append);
		Thread.sleep(1000);
	}

}
